package com.syni.mdd.yhd.common.all.controller.api;

import com.alibaba.fastjson.JSON;
import com.syni.mdd.yhd.common.all.service.BmsVideoService;
import com.syni.mdd.yhd.common.all.utils.ParamData;
import com.syni.mdd.yhd.common.all.utils.WebUtils;
import com.syni.mdd.sjb.common.component.utils.common.utils.ParamsMap;
import com.syni.mdd.sjb.common.component.utils.common.utils.RpcResponseVo;
import com.syni.mdd.sjb.common.component.utils.feign.service.mddAll.VideoRestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @className ApiVideoController
 * @description TOO
 * @Author cfx
 * @DATE 2019/12/31 15:54
 * @VERSION 1.0
 **/
@RestController
@RequestMapping("/video")
public class ApiVideoController implements VideoRestService {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    BmsVideoService bmsVideoService;

    @GetMapping("/decryption")
    @ResponseBody
    public byte[] decryption(){
        byte[] dkBin = null;
        ParamData paramData = new ParamData();
        System.out.println(paramData);
        logger.info(JSON.toJSONString(paramData));
        String fileId = paramData.getString("fileId");
        String keySource = paramData.getString("keySource");
        String token = WebUtils.MD5(fileId + keySource).toLowerCase();
        String argsToken = paramData.getString("token");
        String edk = paramData.getString("edk");
        if(token.equals(argsToken)){
            return bmsVideoService.getDecryptionData(edk);
        }
        return dkBin;
    }

    @Override
    public RpcResponseVo timeToCancel(Integer videoId) {
        return null;
    }

    @Override
    public RpcResponseVo insertMtMachineVideo(ParamsMap paramsMap) {
        return null;
    }
}
